import request from '@/utils/request';
const { NODE_ENV } = process.env;

var prefix=""
if(NODE_ENV=='development'){
  prefix='/api'
}else{
  prefix='http://192.168.0.110:8080'
}
// 查询菜单列表
export function listMenu(query) {
  return request(prefix+'/system/menu/list',{
    method: 'get',
    params: query,
  });
}

// 查询菜单详细
export function getMenu(menuId) {
  return request(prefix+'/system/menu/' + menuId,{
    method: 'get'
  });
}

// 查询菜单下拉树结构
export function treeselect() {
  return request(prefix+'/system/menu/treeselect', {
    method: 'get',
  });
}

// 根据角色ID查询菜单下拉树结构
export function roleMenuTreeselect(roleId) {
  return request(prefix+'/system/menu/roleMenuTreeselect/' + roleId, {
    method: 'get',
  });
}

// 新增菜单
export function addMenu(data) {
  return request(prefix+'/system/menu',{
    method: 'post',
    data: data,
  });
}

// 修改菜单
export function updateMenu(data) {
  return request(prefix+'/system/menu',{
    method: 'put',
    data: data,
  });
}

// 删除菜单
export function delMenu(menuId) {
  return request( prefix+'/system/menu/' + menuId,{
    method: 'delete'
  });
}

//部分参数修改
export function deeps(arr) {
  arr.forEach((v, i) => {
    v.title = v.label;
    v.key = v.id;
    v.value = v.id;
    // v.title=v.menuName
    // v.value=v.menuId
    if (v.children) {
      deeps(v.children);
    }
  });
  return arr;
}


//部分参数修改
export function deeps2(arr) {
  arr.forEach((v, i) => {
    v.title=v.menuName
    v.value=v.menuId
    if (v.children) {
      deeps(v.children);
    }
  });
  return arr;
}
